home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / bor_ti.exe / TI1040.ASC < prev    next >
Text File  |  1992-10-26  |  4KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1040
  9.   VERSION  :  3.1
  10.        OS  :  DOS
  11.      DATE  :  October 26, 1992                         PAGE  :  1/2
  12.  
  13.     TITLE  :  Creating a .WAV resource and using sndPlaySound().
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.   QUESTION:
  21.        How to you place a wave file into resource file and play
  22.        the resource with sndPlaySound function?
  23.  
  24.   ANSWER:
  25.        First, let us examine how to place a wave file into a
  26.        resource file.
  27.  
  28.        To place the file(s) into resource file modifying the
  29.   resource file to contain the following line:
  30.  
  31.             {name} {type} "{file name}"
  32.  
  33.        where
  34.                  {name}         - The name of the resource.
  35.                  {type}         - Resource type. 'SOUND' is the
  36.                                   usual custom resource type.
  37.                  {file name}    - The full path name of the file or
  38.                                   just the file name if is in the
  39.                                   same directory as the resource
  40.                                   file.
  41.  
  42.        The following steps can be used with Resource Workshop:
  43.  
  44.             1) Resource->New->NewType
  45.             2) Type in "ID_SOUND" or "ID_WAVE".
  46.             3) If you type yes for creating a resource id make
  47.                sure you have access to that symbol.  For now
  48.                press No.
  49.             4) Resource->New and choose "SOUND" resource type.
  50.                This will bring up a text editor. Edit the text to
  51.                look similar to the syntax mentioned in the
  52.                section above.
  53.  
  54.  
  55.             NOTE:  Wave files usually takes a lot of memory which
  56.                    means you might have very large resource files.
  57.  
  58.        Now, let us examine how to access the wave file and play it
  59.   from the application.   The following code can be used to load
  60.   and play the resource.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1040
  75.   VERSION  :  3.1
  76.        OS  :  WIN
  77.      DATE  :  October 26, 1992                         PAGE  :  2/2
  78.  
  79.     TITLE  :  Creating a .WAV resource and using sndPlaySound().
  80.  
  81.  
  82.  
  83.  
  84.             LPCSTR sound;   // A pointer to the binary wave file.
  85.  
  86.             hResource = LoadResource( hInst,
  87.                                       FindResource( hInst,
  88.                                                     MAKEINTRESOURCE(ID_SOUND),
  89.                                                    "SOUND" ) );
  90.  
  91.             sound     = ( LPCSTR )LockResource( hResource );
  92.             sndPlaySound( sound, SND_MEMORY );
  93.  
  94.             UnlockResource( hResource );
  95.             FreeResource( hResource );
  96.  
  97.  
  98.   In the code above our resource type is "SOUND" and the resource
  99.   identifier ID_SOUND.  We first use FindResource API function to
  100.   find the resource.  This function returns a handle to the
  101.   resource.  This handle is passed to the LoadResource which
  102.   returns a handle to a copy of the resource in memory.  The
  103.   LockResource is next used to get a pointer to the resource.  Once
  104.   a pointer is available, the latter can be used in a call to the
  105.   sndPlaySound() function.  The second parameter, SND_MEMORY, is
  106.   used to denote that the first parameter is a pointer an in memory
  107.   copy of the wave file.
  108.  
  109.   If you would like to obtain a running sample application using
  110.   sndPlaySound with a resource file you can download the file
  111.   "SOUNDRC.ZIP" from our BBS, CompuServe, BIX, and Genie.
  112.  
  113.   For more information about sndPlaySound and the other API
  114.   function refer to online helps (BCW Reference Guide and
  115.   Multimedia Guide).
  116.  
  117.  
  118.  
  119.   DISCLAIMER: You have the right to use this technical information
  120.   subject to the terms of the No-Nonsense License Statement that
  121.   you received with the Borland product to which this information
  122.   pertains.
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.